package com.uchiha.nova.mainService.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.uchiha.nova.mainService.service.ITenantUserService;
import com.uchiha.nova.mainService.wrapper.TenantUserWrapper;
import com.uchiha.nova.core.tool.constant.NovaCRUDMethodConstant;
import com.uchiha.nova.core.model.dto.TenantUserDTO;
import com.uchiha.nova.core.model.entity.TenantUserEntity;
import com.uchiha.nova.core.model.query.TenantUserQuery;
import com.uchiha.nova.core.model.vo.TenantUserVO;
import com.uchiha.nova.core.tool.api.R;
import com.uchiha.nova.core.tool.support.BaseController;
import com.uchiha.nova.core.tool.support.Condition;
import com.uchiha.nova.core.tool.support.QueryContext;
import com.uchiha.nova.core.tool.util.BeanUtil;
import com.uchiha.nova.core.tool.util.Func;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;


/**
 * 租户账户扩展表 控制器
 *
 * @author magic
 */
@RestController
@AllArgsConstructor
@RequestMapping("/tenantUser")
@Tag(name = "租户账户扩展表")
@Slf4j
public class TenantUserController extends BaseController {

    @Resource
    ITenantUserService tenantUserService;

    /**
     * 详情
     */
    @PostMapping(NovaCRUDMethodConstant.NOVA_DETAIL)
    @Operation(summary = "详情")
    public R<TenantUserVO> detail(@RequestBody TenantUserDTO tenantUserDTO) {
        TenantUserEntity tenantUserEntity = BeanUtil.copy(tenantUserDTO, TenantUserEntity.class);

        TenantUserEntity detail = tenantUserService.getOne(Condition.getQueryWrapper(tenantUserEntity));
        TenantUserVO tenantUserVO = TenantUserWrapper.build().entityVO(detail);
        return R.data(tenantUserVO);
    }

    /**
     * 分页 代码自定义代号
     */
    @GetMapping(NovaCRUDMethodConstant.NOVA_LIST)
    @Operation(summary = "分页查询")
    public R getPage(TenantUserQuery query, QueryContext queryContext) {
        IPage<TenantUserEntity> pages = tenantUserService.page(Condition.getPage(queryContext), Condition.getQueryWrapper(query, queryContext, TenantUserEntity.class));
        return R.data(TenantUserWrapper.build().pageVO(pages));
    }

    /**
     * 新增 代码自定义代号
     */
    @PostMapping(NovaCRUDMethodConstant.NOVA_SAVE)
    @Operation(summary = "新增")
    public R save(@RequestBody TenantUserDTO tenantUserDTO) {
        return tenantUserService.saveInit(tenantUserDTO);
    }

    /**
     * 修改 代码自定义代号
     */
    @PostMapping(NovaCRUDMethodConstant.NOVA_UPDATE)
    @Operation(summary = "修改")
    public R update(@RequestBody TenantUserDTO tenantUserDTO) {
        return tenantUserService.updateTenantUser(tenantUserDTO);
    }

    /**
     * 新增或修改 代码自定义代号
     */
    @PostMapping(NovaCRUDMethodConstant.NOVA_SAVEORUPDATE)
    @Operation(summary = "新增或修改")
    public R saveOrUpdate(@RequestBody TenantUserEntity tenantUserEntity) {
        return R.status(tenantUserService.saveOrUpdate(tenantUserEntity));
    }


    /**
     * 删除 代码自定义代号
     */
    @PostMapping(NovaCRUDMethodConstant.NOVA_REMOVE)
    @Operation(summary = "逻辑删除")
    public R remove(@RequestParam String ids) {
        return R.status(tenantUserService.deleteLogic(Func.toLongList(ids)));
    }

    /**
     * 物理删除，不可恢复
     */
    @Operation(summary = "物理删除")
    @DeleteMapping(NovaCRUDMethodConstant.NOVA_DELETE)
    public R delete(@RequestParam String ids) {
        return R.status(tenantUserService.deletePhysics(Func.toLongList(ids)));
    }


}
